home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10894 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  111 lines

  1. Path: uuneo.neosoft.com!usenet
  2. From: Wmatthew@lan-aces.com (W. Matthews)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: HELP! error(3328)"class template .. has already been defined" when using multiple files
  5. Date: 11 Mar 1996 16:03:25 GMT
  6. Organization: LAN-ACES, Inc.
  7. Message-ID: <4i1isd$b7i@uuneo.neosoft.com>
  8. References: <314366C8.2F1C@st-andrews.ac.uk>
  9. NNTP-Posting-Host: 198.65.178.8
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12. In article <314366C8.2F1C@st-andrews.ac.uk>, Peter Foldiak <Peter.Foldiak@st-andrews.ac.uk> says:
  13. >
  14. >I would like to ask for some help with the following problem.
  15. >(I tried to simplify the files as much as possible).
  16. >When I try to compile the files below on a SG Indy I get the
  17. >following error:
  18. >
  19. >----
  20. >% CC main.c list.c
  21. Have you tried:
  22. % CC list.c main.c
  23. >main.c:
  24. >"list.h", line 1: error(3328): class template "list" has already been
  25. >defined
  26. >  template<class T> class list {
  27. >                          ^
  28. >1 error detected in the compilation of "main.c".
  29. >list.c:
  30. >%
  31. >----
  32. >
  33. >If I concatenate list.c and main.c into a file called listmain.c,
  34. >and compile with
  35. >% CC listmain.c
  36. >%
  37. >the error message disapprears! So I guess it has something to do
  38. >with the bits being in separate files.
  39. >Also, if the files contain no templates there is no error.
  40. >Could anyone please help? Any ideas?
  41. >Is there something special with including headrers when I use templates?
  42. >Thanks!
  43. >
  44. >Peter
  45. >-
  46. >
  47. >===========================================
  48. >The files that won't compile:
  49. >
  50. >list.h:
  51. >-------
  52. >template<class T> class list {
  53. >        T x;
  54. >        list *next;
  55. >public:
  56. >        list<T>::list();
  57. >};
  58. >
  59. >list.c:
  60. >-------
  61. >#include <stdio.h>
  62. >#include "list.h"
  63. >template<class T> list<T>::list()
  64. >{
  65. >        next = NULL;
  66. >}
  67. >
  68. >main.c:
  69. >-------
  70. >#include "list.h"
  71. >int main()
  72. >{
  73. >        list<int> q;
  74. >        return 0;
  75. >}
  76. >
  77. >
  78. >=======================================
  79. >This file compiles without error:
  80. >listmain.c:
  81. >-----------
  82. >#include <stdio.h>
  83. >#include "list.h"
  84. >
  85. >template<class T> list<T>::list()
  86. >{
  87. >        next = NULL;
  88. >}
  89. >
  90. >int main()
  91. >{
  92. >        list<int> q;
  93. >        return 0;
  94. >}
  95. >
  96. >-- 
  97. >Peter Foldiak                     http://psych.st-and.ac.uk:8080/~pf2
  98. >Psychological Laboratory          phone: +44 1334 462087
  99. >University of St Andrews          fax:   +44 1334 463042
  100. >St Andrews KY16 9JU, U.K.         e-mail: Peter.Foldiak@st-and.ac.uk
  101.  
  102. ______________________________________________
  103. |Wyatt Matthews:       Tech Support Department |
  104. |WMATTHEW@LAN-ACES.COM        -Internet-       |
  105. |WMATTHEW.MHS@LAN-ACES          -MHS-          |
  106. |LAN-ACES Tech Support      (713)890-9786      |
  107. |LAN-ACES BBS               (713)890-9790      |
  108. |LAN-ACES Fax               (713)890-9731      |
  109. |LAN-ACES Sales             (713)890-9787      |
  110. ______________________________________________
  111.